#!/usr/bin/env python
# -*- coding: utf-8 -*-

class VBox:
    def __init__(self):
        self.parent = None
        self.children = [ ]
    
    def add(self, widget, proportion):
        widget.parent = self
        self.children.append((widget, proportion))
    
    def compute(self, rect):
        self.rect = rect
        total = 0.0
        for child in self.children:
            total += child[1]
        
        i = 0.0
        for child in self.children:
            child[0].compute((rect[0], rect[1] + rect[3] * i / total, rect[2], rect[3] * child[1] / total))
            i += child[1]
    
    def draw(self, window):
        for child in self.children:
            child[0].draw(window)
    
    def active(self):
        return False
    
    def focus(self):
        for child in self.children:
            focused = child[0].focus()
            if focused != None: return focused
        return None
    
    def blur(self):
        pass
